/**
 * copyright (c) 2017-2023 厦门风领科技有限公司
 * https://www.fengling.cn/
 * 
 * VIVO快游戏适配
 * zengbinsi
 * 2020-08-15 15:32:33
 * 2023-10-23 15:33:37
 */



window.gg = window.gg || {};

if (gg.isQuickGameVIVO) {
    console.log('[TS-API] ===>>>', '适配VIVO小游戏平台');

    gg.channel = gg.EChannelType.QG_VIVO;

    // 小游戏跳转
    gg.navigateToMiniProgram = gg.navigateToMiniGame || (() => { });

    // 广告 
    /** 创建Banner广告 */
    gg._createBannerAdVIVO = gg.createBannerAd;
    gg.createBannerAd = (data) => {
        data.posId = data.adUnitId || data.posId;
        return gg._createBannerAdVIVO(data);
    };

    /** 创建激励式视频广告 */
    gg._createRewardedVideoAdVIVO = gg.createRewardedVideoAd;
    gg.createRewardedVideoAd = (data) => {
        data.posId = data.adUnitId || data.posId;
        return gg._createRewardedVideoAdVIVO(data);
    };

    /** 创建插屏广告 */
    gg._createInterstitialAdVIVO = gg.createInterstitialAd;
    gg.createInterstitialAd = (data) => {
        data.posId = data.adUnitId || data.posId;
        return gg._createInterstitialAdVIVO(data);
    };

    /**九宫格*/
    gg._createGamePortalAdVIVO = gg.createBoxPortalAd;
    gg.createGamePortalAd = (data) => {
        data.posId = data.adUnitId || data.posId;
        return gg._createGamePortalAdVIVO(data);
    };

    gg.setStorage = (object, defaultVal) => {
        const key = object.key;
        const value = object.data;
        const res = qg.setStorage({ key, value });
        return gg.isEmpty(res) ? defaultVal : res;
    };

    gg.getStorageSync = (key, defaultVal) => {
        let res = qg.getStorageSync({ key });
        return gg.isEmptyString(res) ? defaultVal : res;
    };

    gg.setStorageSync = (object, defaultVal) => {
        const key = object.key;
        const value = object.data;
        let res = qg.setStorageSync({ key, value });
        return gg.isEmpty(res) ? defaultVal : res;
    };

    gg.removeStorage = (object, defaultVal) => {
        const key = object.key;
        const res = qg.deleteStorageSync({ key });
        return gg.isEmpty(res) ? defaultVal : res;
    };

    gg.showToast = (data) => {
        let time = data.duration > 1.5 ? 0 : 1;
        qg.showToast({
            message: data.title || '',
            duration: time,
        });
    };
}
